#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#

import pymysql
from flask import Flask
from flask_login import LoginManager
from flask_sqlalchemy import SQLAlchemy
from flask_session import Session

db = SQLAlchemy()
sess = Session()
# basedir = os.path.abspath(os.path.dirname(__file__))
login_manager = LoginManager()
login_manager.session_protection = 'strong'
login_manager.login_view = 'auther.login'

def create_app():
    app = Flask(__name__)

    app.config.from_pyfile('config.py')

    # 初始化数据
    db.init_app(app)
    # 初始化登陆login
    login_manager.init_app(app)
    # 初始化session
    sess.init_app(app)

    pymysql.install_as_MySQLdb()

    # 导入首页
    from app.backend import backend_blue
    # 导入防火墙
    from app.fwmap import fwmap
    # 导入认证
    from app.authentication import auther
    # 导入项目信息管理
    from app.manage import manage

    # 注册首页蓝图
    app.register_blueprint(backend_blue)
    # 注册防火墙蓝图
    app.register_blueprint(fwmap, url_prefix='/fwmap')
    # 注册认证蓝图
    app.register_blueprint(auther, url_prefix='/auth')
    # 注册信息管理
    app.register_blueprint(manage, url_prefix='/manage')

    return app
